#include "Sprite.h"
#define ____MIN_V_ 100
#define ____MAX_V_ (____MIN_V_ + 200)
Sprite::Sprite() : Entity2D()
	{
		vertexs = new TEX_VERTEX[4];

		if(vertexs == NULL)
		{
			assert(false);
		}
		texture = NULL;
		u = 1.0f;
		v = 1.0f;
		this->resetVertexs();
	}

	void Sprite::SetTexture(tex_ptr* texture)
	{
		this->texture = texture;
	}

	void Sprite::resetVertexs()
	{
		vertexs[0].x = ____MIN_V_;
		vertexs[0].y = ____MIN_V_;
		vertexs[0].z = 0;
		vertexs[0].U = 0.0f;
		vertexs[0].V = 0.0f;

		vertexs[1].x = ____MAX_V_;
		vertexs[1].y = ____MIN_V_;
		vertexs[1].z = 0;
		vertexs[1].U = u;
		vertexs[1].V = 0.0f;

		vertexs[2].x = ____MIN_V_;
		vertexs[2].y = ____MAX_V_;
		vertexs[2].z = 0;
		vertexs[2].U = 0.0f;
		vertexs[2].V = v;

		vertexs[3].x = ____MAX_V_;
		vertexs[3].y = ____MAX_V_;
		vertexs[3].z = 0;
		vertexs[3].U = u;
		vertexs[3].V = v;
	}

	void Sprite::SetU(float U)
	{
		u = U;
	}

	void Sprite::SetV(float V)
	{
		v = V;
	}

	Sprite::~Sprite()
	{
		delete[] vertexs;
	}

	void Sprite::Draw(Renderer * render)
	{
		render->bindTexture(texture);
		render->Draw(vertexs, 4, DrawPrimitives::TRIANGLE_STRIP);
	}